﻿<!DOCTYPE html>

<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8" />
    <title>阿里云动态域名解析管理后台</title>
    <script>
        function GetAlyDdnsStatus() {
            let xmlhttp = new XMLHttpRequest();
            xmlhttp.onreadystatechange = function () {
                if (xmlhttp.readyState == 4) {// 4 = "loaded"
                    if (xmlhttp.status == 200) {// 200 = OK
                        var status = xmlhttp.responseText;
                        StatusLable.style.color = "black";
                        CtlButton.innerText = "停止";
                        if (status == "False") {
                            StatusLable.style.color = "red";
                            CtlButton.innerText = "启动";
                            
                        }
                        StatusLable.innerText = status;
                    }
                    else {
                        console.log("GetAlyDdnsStatus error");;
                    }
                }
            }
            xmlhttp.open("GET", "/cmd/GetAlyDdnsStatus");
            xmlhttp.send(null);
        }
        function StartAlyDdns() {
            let xmlhttp = new XMLHttpRequest();
            xmlhttp.onreadystatechange = function () {
                if (xmlhttp.readyState == 4) {// 4 = "loaded"
                    if (xmlhttp.status == 200) {// 200 = OK
                        var status = xmlhttp.responseText;
                        setTimeout(GetAlyDdnsStatus, 1000 * 1);
                    }
                    else {
                        console.log("StartAlyDdns error");
                    }
                }
            }
            xmlhttp.open("GET", "/cmd/StartAlyDdns?cfg=" + CfgSelect.value);
            xmlhttp.send(null);
        }
        function StopAlyDdns() {
            let xmlhttp = new XMLHttpRequest();
            xmlhttp.onreadystatechange = function () {
                if (xmlhttp.readyState == 4) {// 4 = "loaded"
                    if (xmlhttp.status == 200) {// 200 = OK
                        var status = xmlhttp.responseText;
                        setTimeout(GetAlyDdnsStatus, 1000 * 1);
                    }
                    else {
                        console.log("StopAlyDdns error");
                    }
                }
            }
            xmlhttp.open("GET", "/cmd/StopAlyDdns");
            xmlhttp.send(null);
        }
        function GetAlyDdnsCfgList() {
            let xmlhttp = new XMLHttpRequest();
            xmlhttp.onreadystatechange = function () {
                if (xmlhttp.readyState == 4) {// 4 = "loaded"
                    if (xmlhttp.status == 200) {// 200 = OK
                        let text = xmlhttp.responseText;
                        let list = text.split("|");
                        let html = "";
                        for (let i = 0; i < list.length; i++) {
                            html += "<option value='" + list[i] + "'>" + list[i] + "</option>";
                        }
                        CfgSelect.innerHTML = html;
                    }
                    else {
                        console.log("GetAlyDdnsCfgList error");
                    }
                }
            }
            xmlhttp.open("GET", "/cmd/GetAlyDdnsCfgList");
            xmlhttp.send(null);
        }
        function Load() {
            GetAlyDdnsStatus();
            GetAlyDdnsCfgList();
        }
        function ToCtl() {
            if (CtlButton.innerText == "启动") {
                StartAlyDdns();
            }
            else {
                StopAlyDdns();
            }
        }
    </script>
</head>
<body onload="Load()">
    <h1>阿里云动态域名解析</h1>
    <hr />
    <p>服务器当前状态：<span id="StatusLable"></span></p>
    <p>配置：<select id="CfgSelect"></select></p>
    <a href="javascript:ToCtl()" id="CtlButton">启动</a>
    <br />
</body>
</html>